home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / datasheets and manuals / Hardware / WHT / scsi / dsr_sources_2_2001 / openap < prev    next >
Text File  |  2006-10-19  |  6KB  |  247 lines

  1. **
  2. *
  3. * OPEN APPEND and OPEN UPDATE
  4. *
  5. * This procedure checks to see if a file exists.  If it does
  6. * not, it just transfers control to OPENOU to create the file.
  7. * If the file exists, it checks to make sure the file is not
  8. * protected, and its attributes match.
  9. *
  10. * If the file is being opened in append mode, it reads the sector
  11. * that contains the end of file marker and points to the end
  12. * of file.
  13. *
  14. * If the file is being opened in update mode, then file pointer
  15. * is set to the beginning of the file and no data is read in.
  16. *
  17. **
  18.  
  19. OPENUP
  20. OPENAP
  21.        BL   @GETFDR
  22.        CI   R5,0
  23.        JNE  OAP1
  24.        B    @OOU20            File doesn't exist - create it
  25.  
  26. OAP1   LDCR @ZERO,4           Select RAM bank 0
  27.        MOVB @12(R5),R1        Get file flags
  28.        CZC  @PROBIT,R1        Check protection bit
  29.        JEQ  OAP2
  30.        BL   @DSRERR           File protected - error
  31.        DATA >0100
  32.  
  33. OAP2
  34.        ANDI R1,>0100          Check for Data/Program
  35.        JEQ  OAP3
  36. OAPBAD BL   @DSRERR
  37.        DATA >0200             Bad open attribute
  38.  
  39. OAP3   MOVB @12(R5),R1        Check Fixed/variable
  40.        ANDI R1,>8000
  41.        MOVB @PABBUF+1,R2
  42.        ANDI R2,>1000
  43.        SLA  R2,3
  44.        C    R1,R2
  45.        JNE  OAPBAD
  46.  
  47.        MOVB @12(R5),R1        Check Display/Internal
  48.        ANDI R1,>0200
  49.        MOVB @PABBUF+1,R2
  50.        ANDI R2,>0800
  51.        SRL  R2,2
  52.        C    R1,R2
  53.        JNE  OAPBAD
  54.  
  55. * Now compare record length.  If a value of 0 is specified, we
  56. * will write the actual record length in the caller's PAB
  57. *
  58.        MOVB @PABBUF+4,R1
  59.        JEQ  OAP4
  60.        CB   R1,@17(R5)
  61.        JNE  OAPBAD
  62.        JMP  OAP5
  63. OAP4
  64.        MOV  @PABADR,R0        Write out actual record length
  65.        AI   R0,4
  66.        ORI  R0,>4000          into caller's PAB
  67.        SWPB R0
  68.        MOVB R0,@VDPWA
  69.        SWPB R0
  70.        MOVB R0,@VDPWA
  71.        NOP
  72.        MOVB @17(R5),@VDPWD
  73.  
  74. * Set up the open file cache entry
  75. OAP5
  76.        BL   @OSCASH
  77.  
  78. * Lets copy the FDR to it's buffer in bank 5
  79. *
  80.        LI   R0,256
  81.        MOV  @4(R4),R3        Get FDR address
  82.        MOVB @2(R4),R2        Get FDR bank
  83. OAP6   LDCR @ZERO,4
  84.        MOV  *R5+,R1
  85.        LDCR R2,4
  86.        MOV  R1,*R3+
  87.        DECT R0
  88.        JNE  OAP6
  89.        AI   R3,-256          Restore pointer to FDR
  90.  
  91. * If we're opening the file for UPDATE mode, we can end
  92. * here.  Otherwise we have to read in the last sector and
  93. * adjust the file pointers accordingly.
  94. *
  95. * Now we have to compute what AU contains the end of file,
  96. * read it into the buffer and set some pointers.
  97. *
  98.        LDCR @ZERO,4
  99.        MOVB @PABBUF+1,R1     Get file flags
  100.        ANDI R1,>0600         Mask out Mode of Operation
  101.        JNE  OAP8A
  102.  
  103.        B    @DSRRT           UPDATE access - we're done!
  104.  
  105. OAP8A  LDCR R2,4
  106.        MOV  @18(R3),R11      Get last record read or last sector written
  107.        JNE  OAP8B            If file is empty, we're done!
  108.        LDCR @ZERO,4
  109.        B    @DSRRT
  110. OAP8B
  111.        SWPB R11
  112.        DEC  R11
  113.        CLR  R10
  114.  
  115. * If it is a fixed length record file, we have to divide by the
  116. * number of records per sector to get sectors
  117. *
  118.        MOVB @12(R3),R1       Get file flags
  119.        ANDI R1,>8000
  120.        JNE  OAP9
  121.  
  122.        MOVB @13(R3),R1       Get # of records/sector
  123.        SRL  R1,8
  124.        DIV  R1,R10
  125.        MOV  R10,R11
  126.        CLR  R10
  127. OAP9
  128.        LDCR @B04,4
  129.        MOVB R6,R1
  130.        SRL  R1,8
  131.        SLA  R1,1
  132.        DIV  @SAUTBL(R1),R10  Divide by sectors per AU
  133.  
  134. * Now R10 contains the AU that has the end of file.  Traverse
  135. * through the file's data chain to find the physical AU
  136. *
  137.  
  138.        AI   R3,40
  139.        LDCR R2,4
  140.  
  141. OAP10  MOV  *R3+,R7
  142. OAP11  CI   R10,0
  143.        JEQ  OAP13
  144. OAP11A C    R7,*R3
  145.        JNE  OAP12
  146.        INCT R3
  147.        DEC  R10
  148.        JMP  OAP10
  149.  
  150. OAP12  INC  R7
  151.        DEC  R10
  152.        JNE  OAP11A
  153.  
  154. OAP13
  155.  
  156. * Save the AU and sector within AU in the cache entry
  157. *
  158.        LDCR @B02,4
  159.        MOV  R7,@50(R4)       Save current AU
  160.        MOV  R11,@52(R4)      Save sector within AU
  161.  
  162. * Now that we have the AU, add in the sector within AU (R11)
  163. * and read it from disk.
  164. *
  165.  
  166.        LDCR @B04,4
  167.        MOV  R6,R1
  168.        SRL  R1,8
  169.        SLA  R1,1
  170.        MPY  @SAUTBL(R1),R7
  171.        A    R11,R8
  172.        JNC  OAP14
  173.        INC  R7
  174. OAP14
  175.        LI   R1,SECBUF
  176.        SRL  R8,1
  177.        JNC  OAP15
  178.        AI   R1,>100
  179. OAP15  SRL  R7,1
  180.        JNC  OAP16
  181.        AI   R8,>8000
  182. OAP16
  183.        LDCR @ZERO,4
  184.        BLWP @BANKIT
  185.        DATA SCSIRD
  186.        JEQ  OAP17
  187.  
  188.        BL   @DSRERR
  189.        DATA >0600            Device Error
  190.  
  191. OAP17
  192.  
  193. * Copy the data from the SCSI buffer to the file buffer
  194. *
  195.        LDCR @B02,4
  196.        MOV  @6(R4),R5        Get buffer pointer
  197.        MOVB @3(R4),R2        Get buffer bank
  198.  
  199. * Set the pointer in buffer to the base plus the end of
  200. * file offset.
  201.  
  202.        MOV  R5,@54(R4)       Reset pointer within buffer
  203.        MOV  @4(R4),R3        Get FDR address
  204.        LDCR @2(R4),4
  205.        MOV  @18(R3),R8       Get # of level 3
  206.        SWPB R8
  207.        MOVB @16(R3),R0       Get end of file offset
  208.        SRL  R0,8
  209.        LDCR @B02,4
  210.        A    R0,@54(R4)
  211.        MOV  R8,@62(R4)
  212.  
  213. * Now for a fixed length file we need to add one more.
  214.  
  215.        LDCR @2(R4),4
  216.        MOVB @12(R3),R0       Get file flags
  217.        ANDI R0,>8000
  218.        JNE  OAP17A
  219.        LDCR @B02,4
  220.        INC  @54(R4)
  221. OAP17A
  222.  
  223. * See if we can use a 512 byte buffer
  224.  
  225.        CI   R1,SECBUF
  226.        JNE  OAP18
  227.        LDCR @B04,4
  228.        MOV  R6,R3
  229.        SRL  R3,8
  230.        SLA  R3,1
  231.        MOV  @SAUTBL(R3),R3
  232.        CI   R3,2
  233.        JL   OAP18
  234.  
  235.        LDCR @B02,4
  236.        SETO @58(R4)          Set buffer size to 512
  237.  
  238. OAP18  LDCR @ZERO,4
  239.        MOV  *R1+,R0
  240.        LDCR R2,4
  241.        MOV  R0,*R5+
  242.        CI   R1,SECBUF+512
  243.        JNE  OAP18
  244. OAP50
  245.        LDCR @ZERO,4
  246.        B    @DSRRT
  247.